@isTest
private class PA_Update_Percentage_Test_Class {

  static testMethod void myUnitTest() {
        // TO DO: implement unit test
        User u = new User(Lastname = 'Test1', Username = 'sampleuser112143@gmail.com', Email = 'sampleuser@gmail.com', Alias = 'test', CommunityNickname = 'sample', TimeZoneSidKey = 'America/Los_Angeles', LocaleSidKey = 'en_US', EmailEncodingKey = 'ISO-8859-1', ProfileId = UserInfo.getProfileId(), LanguageLocaleKey = 'en_US', ManagerId = UserInfo.getUserId());        
        User u1 = new User(Lastname = 'Test2', Username = 'sampleuser2159@gmail.com', Email = 'sampleuser2@gmail.com', Alias = 'test2', CommunityNickname = 'sample2', TimeZoneSidKey = 'America/Los_Angeles', LocaleSidKey = 'en_US', EmailEncodingKey = 'ISO-8859-1', ProfileId = UserInfo.getProfileId(), LanguageLocaleKey = 'en_US', ManagerId = UserInfo.getUserId());
        
        Opportunity O = new Opportunity (
            Name = 'Test Opportuniy 001',
            StageName = 'Follow Up Call / E-mail / Meeting',
            CloseDate = date.today() 
        );

        test.startTest();
        insert o;
        
        Opportunity [] oList = [select id, name, Opportunity_Percentage_Allocated__c, OwnerId from Opportunity where id = :o.id];

        insert u;

        Productivity_Allocations__c pa = new Productivity_Allocations__c ( 
                                Opportunity_Name__c = oList[0].Id, 
                                Sales_Associate__c = u.Id,
                                Allocation_Percentage__c = 0);

        try
        {
            insert pa;
        }
        catch(Exception e){}

        Productivity_Allocations__c[] paList = [select id, Allocation_Percentage__c, Opportunity_Name__c 
                                        from Productivity_Allocations__c 
                                        where id = :pa.id];

        //for example update allocation percentage
        paList[0].Allocation_Percentage__c = 100;
        
        try
        {
            update paList;
        }
        catch(Exception e){}

        paList = [select id, Sales_Associate__c, Allocation_Percentage__c, Opportunity_Name__c from Productivity_Allocations__c order by createddate limit 1];
  
        insert u1;

        paList[0].Sales_Associate__c = u1.id;
        try
        {
            update paList;
        }
        catch(Exception e){}
        test.stoptest();
    }
}